package com.letv.whatslive.model.convert;

import com.letv.whatslive.model.PreloadDeviceAndApp;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created by Administrator on 2016/4/29.
 */
public class PreloadDeviceAndAppConvert {
    public static DBObject castPreloadDeviceAndAppToDBObject(PreloadDeviceAndApp preloadDeviceAndApp){
        DBObject dbo = new BasicDBObject();
        if(preloadDeviceAndApp.getId() != null){
            dbo.put("_id",preloadDeviceAndApp.getId());
        }
        if(preloadDeviceAndApp.getDeviceId() != null)
            dbo.put("deviceId",preloadDeviceAndApp.getDeviceId());

        if(preloadDeviceAndApp.getAppId() != null)
            dbo.put("appId",preloadDeviceAndApp.getAppId());

        if(preloadDeviceAndApp.getSysType() != null)
            dbo.put("sysType",preloadDeviceAndApp.getSysType());


        if(preloadDeviceAndApp.getSysVersion() != null)
            dbo.put("sysVersion",preloadDeviceAndApp.getSysVersion());

        return dbo;


    }

    public static PreloadDeviceAndApp castDBObjectToPreloadDeviceAndApp(DBObject dbObject){
        PreloadDeviceAndApp preloadDeviceAndApp = new PreloadDeviceAndApp();
        if(dbObject != null) {
            preloadDeviceAndApp.setId(ObjUtils.toLong(dbObject.get("_id")));
            preloadDeviceAndApp.setDeviceId(ObjUtils.toLong(dbObject.get("deviceId")));
            preloadDeviceAndApp.setAppId(ObjUtils.toLong(dbObject.get("appId")));
            preloadDeviceAndApp.setSysType(ObjUtils.toInteger(dbObject.get("sysType")));
            preloadDeviceAndApp.setSysVersion(ObjUtils.toString(dbObject.get("sysVersion")));
        }

        return preloadDeviceAndApp;
    }
}
